package com.example.demo.async;

import com.example.demo.entity.UserInfo;
import com.example.demo.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;
import java.util.concurrent.Future;

/**
 * @author LF
 * @date 2021/4/19 - 17:47
 */
@Service
public class TestAsynvServiceImpl implements TestAsyncService{

    @Autowired
    private UserInfoService userInfoService;

    @Override
    public Future<String> getUserInfo(Long id) {
        UserInfo userInfo = userInfoService.getById(id);
        if (Objects.isNull(userInfo)){
            return new AsyncResult<String>("");
        }
        return new AsyncResult<String>(userInfo.getUseName());
    }

    @Override
    public void getAll() {
        List<UserInfo> list = userInfoService.list();
        list.forEach(System.out::println);
    }
}
